import java.util.TreeSet;

public class Solution849 {
    public int maxDistToClosest(int[] seats) {
        TreeSet<Integer> treeSet=new TreeSet<>();
        for (int i=0;i<seats.length;i++){
            if (seats[i]==1){
                treeSet.add(i);
            }
        }
        int ans=Integer.MIN_VALUE;
        for (int i=0;i<seats.length;i++){
            if (seats[i]==0) {
                Integer a=treeSet.ceiling(i);
                Integer b=treeSet.floor(i);
                int dis=Integer.MAX_VALUE;
                if (a!=null){
                    dis=Math.min(dis,Math.abs(i-a));
                }
                if (b!=null){
                    dis=Math.min(dis,Math.abs(i-b));
                }
                ans=Math.max(ans,dis);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution849().maxDistToClosest(new int[]{1,0,0,0,1,0,1}));
    }
}
